<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link href="${servurl}/js/jquery-validation-1.13.1/form.css" rel="stylesheet" />
    <link rel="stylesheet" href="${servurl}/css/bootstrap.min.css">
    <link rel="stylesheet" href="${servurl}/css/proint/users/land.css">
    <link rel="stylesheet" href="${servurl}/js/skin/layer.css">
    
    <style type="text/css">
    * {
		margin: 0;
		padding: 0;
		font-family: "微软雅黑";
	}
	label.error {
	    color: red;
	    font-size: 14px;
	    position: relative;
	    text-align: center;
	    top: 0px;
	    width: 100%;
	    float:left; 
	}
    </style>
    
    <script type="text/javascript" src="${servurl}/js/jquery-1.10.2.min.js"></script>
   	<script type="text/javascript" src="${servurl}/js/jquery-validation-1.13.1/jquery.validate.min.js"></script>
	<script type="text/javascript" src="${servurl}/js/jquery-validation-1.13.1/localization/messages_zh.js"></script>
	<script type="text/javascript" src="${servurl}/js/jquery-validation-1.13.1/additional-methods.min.js"></script>
	<script type="text/javascript" src="${servurl}/js/jquery-validation-1.13.1/jquery-validate-extend.js"></script>
   	<script type="text/javascript" src="${servurl}/js/RSA.js"></script>
   	<script type="text/javascript" src="${servurl}/js/jquery.cookie.js"></script>
   	
   	<script src="${servurl}/js/layer/layer.js" type="text/javascript"></script>
   	
    <script type="text/javascript">
    		
    
    		$(function(){
    			//记住账号
	            $('#jizhu').click(function(){
	                var account=$('#account').val();
	                var flag=$(this).is(':checked');
	                if(flag){
	                	$.cookie("account",account,{expires:7});
	                	$.cookie("password","");  
	                }else{
	                	$.cookie("account","",{expires:7});
	                	$.cookie("password","");
	                }
	            });
	            
    			//绑定提交表单事件
    			$("#myform").submit(function(){
    				if($("#myform").valid()==true){
    					loginSubmit();
    				}
    				return false;
    			});
    			
    			//绑定提交表单事件
    			$("#form2").submit(function(){
    				if($("#form2").valid()==true){
    					if($("#new_password").val()==$("#new_password_ok").val()){
    						changeSubmit();	
    					}else{
    						layer.msg("新密码两次输入不一致，请重新输入");
    					}
    				}
    				return false;
    			});
    			
    			$("#myform").validate();
    			$("#form2").validate();
    		});
    		
    		//修改密码
    		function changeSubmit(){
    			$.ajax({
    				type : 'post',
    				url : "member/memberUpdate.do",
    				data :{
    					'phone':$("#phone").val(),
    					'password':encrypt($("#oldpassword").val()),
    					'newPassword':encrypt($("#new_password").val())
    				},
    				dataType : 'json', 
    				success : function(data){ 
    					/* alert(JSON.stringify(data));*/
    					if(data.resultMsg==1){
    						layer.msg("密码修改成功，请重新登录！");
							setTimeout('jumpurl()',3000);  
    					}else{
    						layer.msg("密码修改失败");
    					}
    				}
    			});
    			return false;
    		}
    		
    		function jumpurl(){  
			  window.location='login.do';  
			} 
    		
    		function login(){
    			$("#myform").submit();
    		}
    		
    		//加密
    		function encrypt(pwd){
    			RSAUtils.setMaxDigits(200);
    			var key = new RSAUtils.getKeyPair("${publicKeyExponent}", "", "${publicKeyModulus}");  
    			var encrypedPwd = RSAUtils.encryptedString(key,pwd.split("").reverse().join("")); 
    			return encrypedPwd;
    		}
    		
    		//提交登录
    		function loginSubmit(){
    			$.ajax({
    				type : 'post',
    				url : "member/memberAP.do",
    				data :{
    					'account':$("#account").val(),
    					'password':encrypt($("#password").val())
    				},
    				dataType : 'json',
    				success : function(data){
    					/* alert(JSON.stringify(data));*/
    					if(data.resultMsg==1){
    						window.location.href="${servurl}/index.do";
    					}else if(data.resultMsg==-3){
    						layer.msg("登录失效");
    					}else if(data.resultMsg==-4){
    						changePwd();
    						layer.msg("首次登录，请先修改密码！");
    					}else if(data.resultMsg==0){
    						layer.msg("登录异常，请联系管理员");
    					}else{
    						layer.msg("登录失败，账号或密码错误！");
    					}
    				}
    			});
    			return false;
    		}
    		
    		
    		function changePwd(){
    			layer.open({
				  type: 1,
				  title: '修改密码',
				  shadeClose: true,
				  shade: 0.8,
				  area: ['600px', '60%'],
				  content: $("#change"),
				  btn: ['确认修改','取消' ]
				  ,yes: function(index, layero){
				     $("#form2").submit();
				  },cancel: function(){
				    //右上角关闭回调
				  }
				});
    		}
    		
    		//加载账号 
    		$(window).load(function(){
			    //要执行的方法体
			    if($.cookie("account")){
	                $('#account').val($.cookie("account"));
	            }
			    $('#password').val("");
			});
    </script> 
    
</head>
<body class="login-body">
    <form id="myform">
    <img src="imges/bg.png" class="bg" id="bg" width="100%" height="100%" style="right: 0; bottom: 0;  position: absolute; top: 0" alt="">
    <div class="container">
      <div class="form-signin">
        <div class="logo"><img src="imges/logo.png" alt=""></div>
        <div class="login-wrap">
            <input type="text" id="account" name="account" class="form-control userid" value="" placeholder="请输入账号" required>
            <div></div>
            <input type="password" id="password" name="password" class="form-control password" placeholder="请输入密码" required>
            <div></div>
            <div class="logo_check">
                <span>
                    <input type="checkbox" id="jizhu" class="checkbox" />
                  	  记住账号        
                </span>
                <a href="javascript:void(0)" onclick="changePwd()">修改密码</a>
            </div>
            <button class="btn btn-lg btn-login btn-block login" onclick="login()" type="button">登录</button>
            
        </div>
      </div>
    </div>
    </form>
     
    <div id="change" style="display:none;">
    	<div style="width:90%;margin:20px auto;">
    		<form id="form2">
    			<input type="text" id="phone" name="phone" isTel="true" class="form-control" placeholder="手机号" required>
    			<div style="height:20px"></div>
    			<input type="password" id="oldpassword" name="oldpassword" class="form-control" placeholder="旧密码" required>
    			<div style="height:20px"></div>
    			<input type="password" id="new_password" name="new_password" class="form-control" placeholder="新密码" required>
    			<div style="height:20px"></div>
    			<input type="password" id="new_password_ok" name="new_password_ok" class="form-control" placeholder="确认新密码" required>
    			<div style="height:20px"></div>
    		</form>
    	</div>
    </div>
    
</body>
</html>